/*    */ package org.yaukie.auth.config;
/*    */ 
/*    */ import java.nio.charset.StandardCharsets;
/*    */ import java.security.MessageDigest;
/*    */ import org.springframework.security.crypto.password.PasswordEncoder;
/*    */ 
/*    */ 
/*    */ 
/*    */ 
/*    */ 
/*    */ public class Md5PasswordEncoder
/*    */   implements PasswordEncoder
/*    */ {
/*    */   private static final String[] HEX_DIGITS = { 
/* 15 */       "0", "1", "2", "3", "4", "5", "6", "7", "8", "9", "a", "b", "c", "d", "e", "f" };
/*    */   
/*    */   private String salt;
/*    */ 
/*    */   
/* 20 */   public void setSalt(String salt) { this.salt = salt; }
/*    */ 
/*    */   
/* 23 */   private static Md5PasswordEncoder instance = new Md5PasswordEncoder();
/*    */ 
/*    */ 
/*    */ 
/*    */ 
/*    */   
/* 29 */   public static Md5PasswordEncoder getInstance() { return instance; }
/*    */ 
/*    */ 
/*    */   
/*    */   private String mergePasswordAndSalt(CharSequence password) {
/* 34 */     if (password == null) {
/* 35 */       password = "";
/*    */     }
/*    */     
/* 38 */     if (this.salt == null || "".equals(this.salt)) {
/* 39 */       return password.toString();
/*    */     }
/* 41 */     return password + "{" + this.salt + "}";
/*    */   }
/*    */ 
/*    */   
/*    */   private String byteArrayToHexString(byte[] b) {
/* 46 */     StringBuilder resultSb = new StringBuilder();
/* 47 */     for (byte value : b) {
/* 48 */       resultSb.append(byteToHexString(value));
/*    */     }
/* 50 */     return resultSb.toString();
/*    */   }
/*    */   
/*    */   private String byteToHexString(byte b) {
/* 54 */     int s = b;
/* 55 */     if (s < 0) {
/* 56 */       s = 256 + s;
/*    */     }
/* 58 */     int d1 = s / 16;
/* 59 */     int d2 = s % 16;
/* 60 */     return HEX_DIGITS[d1] + HEX_DIGITS[d2];
/*    */   }
/*    */ 
/*    */ 
/*    */ 
/*    */ 
/*    */ 
/*    */ 
/*    */ 
/*    */   
/*    */   public String encode(CharSequence rawPassword) {
/* 71 */     String result = null;
/*    */     try {
/* 73 */       String algorithm = "MD5";
/* 74 */       MessageDigest md = MessageDigest.getInstance(algorithm);
/* 75 */       result = byteArrayToHexString(md.digest(mergePasswordAndSalt(rawPassword).getBytes(StandardCharsets.UTF_8)));
/* 76 */     } catch (Exception exception) {}
/*    */     
/* 78 */     return result;
/*    */   }
/*    */ 
/*    */ 
/*    */ 
/*    */ 
/*    */ 
/*    */ 
/*    */ 
/*    */ 
/*    */ 
/*    */   
/* 90 */   public boolean matches(CharSequence rawPassword, String encodedPassword) { return encodedPassword.equals(encode(rawPassword)); }
/*    */ }


/* Location:              /Users/rex/Desktop/x-common-auth-1.0.0-SNAPSHOT.jar!/org/yaukie/auth/config/Md5PasswordEncoder.class
 * Java compiler version: 8 (52.0)
 * JD-Core Version:       1.0.7
 */